package com.eshopkeeper.provider.sys;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.plugins.Page;
import com.eshopkeeper.core.base.BaseProviderImpl;
import com.eshopkeeper.dao.sys.SysDeptMapper;
import com.eshopkeeper.model.sys.SysDept;
import com.eshopkeeper.model.sys.ext.SysDeptBean;
import com.weibo.api.motan.config.springsupport.annotation.MotanService;

/**
 * @author chenshufeng
 * @version 2017年3月17日20日 下午3:19:19
 */
//@CacheConfig(cacheNames = "sysDept")
@MotanService(basicService = "serviceBasicConfig")
public class SysDeptProviderImpl extends BaseProviderImpl<SysDept> implements ISysDeptProvider {

    @Autowired
    private SysDeptMapper sysDeptrMapper;

    public Page<SysDept> query(Map<String, Object> params) {
        Page<Long> page = this.getPage(params);
        page.setRecords(mapper.selectIdByMap(page, params));
        return getPage(page);
    }

    @Override
    public void insertSysDept(SysDept sysDept) {
        sysDeptrMapper.insertSysDept(sysDept);
    }

    @Override
    public List<Map<String, Object>> queryParentList() {
        return sysDeptrMapper.queryParentList();
    }

	@Override
	public Page<SysDeptBean> queryDeptList(Map<String, Object> mapParam) {
		Page<Long> idPage = this.getPage(mapParam);
        List<Long> ids = mapper.selectIdByMap(idPage, mapParam);
        Page<SysDeptBean> pageInfo = new Page<SysDeptBean>(idPage.getCurrent(), idPage.getSize());
        pageInfo.setTotal(idPage.getTotal());
        
        if (ids.size() > 0) {
        	List<SysDeptBean> sysDeptList = sysDeptrMapper.queryDeptList(ids);
        	pageInfo.setRecords(sysDeptList);
        } else {
        	pageInfo.setRecords(null);
        }
        
		return pageInfo;
	}

	@Override
	public void updateSysDept(Map<String, Object> paramMap) {
		sysDeptrMapper.updateSysDept(paramMap);
	}

}
